﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Wuther.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class add_organization : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Organization",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true, comment: "父级ID"),
                    Code = table.Column<string>(type: "text", nullable: false, comment: "编码"),
                    DisplayName = table.Column<string>(type: "text", nullable: false, comment: "显示名称"),
                    AreaCode = table.Column<string>(type: "text", nullable: false, comment: "行政区划"),
                    UserId = table.Column<Guid>(type: "uuid", nullable: false, comment: "负责人ID"),
                    Sort = table.Column<int>(type: "integer", nullable: false, comment: "排序"),
                    Remark = table.Column<string>(type: "text", nullable: false, comment: "备注"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Organization", x => x.Id);
                },
                comment: "部门信息");

            migrationBuilder.CreateTable(
                name: "OrganizationUsers",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    UserId = table.Column<Guid>(type: "uuid", nullable: false, comment: "人员ID"),
                    OrganizationId = table.Column<Guid>(type: "uuid", nullable: false, comment: "单位ID"),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: false, comment: "租户ID"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OrganizationUsers", x => x.Id);
                },
                comment: "人员单位关系");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Organization");

            migrationBuilder.DropTable(
                name: "OrganizationUsers");
        }
    }
}
